﻿using Shinva.Common;
using Shinva.LADModel.Abstractions;
using Shinva.Variables.Interface;
using Shinva.Variables.Type.bit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shinva.LADModel.Models
{
    public class DataPointer : IDataNode
    {
        public IPlcModelService service { get; set; }
        private IPlcMember value { get; set; }

        public IPlcMember Value
        {
            //每次访问Value的时候就去找全局找
            get => GetPlcMember();
            set
            {
                this.value = value;
                //这里可以添加一些逻辑，比如更新UI等
            }
        }

        public int Id { get; set; }
        public NodeType NodeType { get; set; } = NodeType.DataPointer;

        public List<string> Symbols { get; set; } = new List<string>();


        //这里为了得到对应symbol的变量实例 通过依赖注入的方式获取到全局唯一的Service
        public DataPointer(IPlcModelService _service=null)
        {
            service = _service;
        }

        public DataPointer(List<string> symbols)
        {
            Symbols = symbols;
        }

        private IPlcMember GetPlcMember()
        {
            //这里可以添加一些逻辑，比如从数据库中获取变量
            service.GetPlcMember(this.Symbols);
            return null;
        }


    }
}
